#include <string.h>
#include "NavigationEdge.h"
#include "GL/glut.h"

NavigationEdge::NavigationEdge(Vector2D rightEndPoint, Vector2D leftEndPoint, 
					Locomotion rightToLeft, Locomotion leftToRight,
					char ** behaviorTags, int numTags)
{
	this->rightEndPoint = rightEndPoint;
	this->leftEndPoint = leftEndPoint;
	this->rightToLeft = rightToLeft;
	this->leftToRight = leftToRight;
	this->behaviorTags = behaviorTags;
	this->numTags = numTags;
	rightEdges = NULL;
	leftEdges = NULL;
	g = 0;
	h = 0;
	f = 0;
	cameFrom = NULL;
	midpoint = (rightEndPoint + leftEndPoint) * 0.5;
	length = rightEndPoint | leftEndPoint;
}
NavigationEdge::~NavigationEdge()
{
	if(behaviorTags)
	{
		for(int i = 0; i < numTags; i++)
		{
			if(behaviorTags[i])
			{
				delete(behaviorTags[i]);
				behaviorTags[i] = false;
			}
		}
		delete(behaviorTags);
		behaviorTags = NULL;
	}
}
void NavigationEdge::AddLeftEdge(NavigationEdge * edge)
{
	AddEdge(&leftEdges, edge);
}
void NavigationEdge::AddRightEdge(NavigationEdge * edge)
{
	AddEdge(&rightEdges, edge);
}
void NavigationEdge::AddEdge(NavigationEdgeList ** edgeList, NavigationEdge * edge)
{
	if(edge)
	{
		if(*edgeList)
		{
			(*edgeList)->Add(edge);
		}
		else
		{
			(*edgeList) = new NavigationEdgeList(edge);
		}
	}
}
Locomotion NavigationEdge::GetRightToLeft()
{
	return rightToLeft;
}
Locomotion NavigationEdge::GetLeftToRight()
{
	return leftToRight;
}
Vector2D NavigationEdge::GetLeftEndPoint()
{
	return leftEndPoint;
}
Vector2D NavigationEdge::GetRightEndPoint()
{
	return rightEndPoint;
}
Vector2D NavigationEdge::GetMidpoint()
{
	return midpoint;
}
float NavigationEdge::GetLength()
{
	return length;
}
NavigationEdgeList * NavigationEdge::GetRightEdges()
{
	return rightEdges;
}
NavigationEdgeList * NavigationEdge::GetLeftEdges()
{
	return leftEdges;
}
bool NavigationEdge::IsTagged(char * tag)
{
	for(int i=0; i < numTags; i++)
	{
		if(strcmp(tag, behaviorTags[i])==0)
			return true;
	}
	return false;
}
void NavigationEdge::Draw()
{
	glBegin(GL_LINES);
	glVertex2f(rightEndPoint.x, rightEndPoint.y);
	glVertex2f(leftEndPoint.x, leftEndPoint.y);
	glEnd();
}
